package com.cg.exceptionHandler;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author cheyinbo
 * @date 2021-04-07 12:19:30
 */
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {

    @ExceptionHandler(value = RuntimeException.class)
    public String handlerRuntimeException(HttpServletRequest request, HttpServletResponse response, Exception e){
        e.printStackTrace();
        log.info("异常信息:{}",e.getMessage());
        return e.getMessage();
    }

}
